package haemers.serializers.tests 
{
	import flash.utils.Dictionary;
	import haemers.serializers.data.BasicVO;
	import haemers.serializers.data.SerializeVO;
	import nl.haemers.data.serializers.XMLSerializer;
	import nl.haemers.utils.ObjectReader;
	import org.flexunit.Assert;
	/**
	 * ...
	 * @author Jonathan
	 */
	public class XMLSerializerTest 
	{
		[Embed(source="../data/basicdata.xml", mimeType="application/octet-stream")]
		private var basicXML:Class;
		private var _basicXML:XML;
		private var _basicVO:BasicVO;
		
		[Embed(source="../data/serializedata.xml", mimeType="application/octet-stream")]
		private var serializeXML:Class;
		private var _serializeXML:XML;
		private var _serializeVO:SerializeVO;
		
		private var _xmlSerializer:XMLSerializer;
		
		/** Public methods **/
		[Before]
		public function setup() : void
		{
			_xmlSerializer = new XMLSerializer();
			_basicXML = XML(new basicXML());
			
			var result:Array = _xmlSerializer.deserialize(_basicXML, BasicVO);
			Assert.assertEquals(1, result.length);
			_basicVO = result[0];
			
			_serializeXML = XML(new serializeXML());
			var serializeResult:Array = _xmlSerializer.deserialize(_serializeXML, SerializeVO);
			Assert.assertEquals(1, serializeResult.length);
			_serializeVO = serializeResult[0];
		}
		
		[Test]
		public function testDataTypes() : void
		{
			Assert.assertEquals(int(0x00FF00), _basicVO.color);
			Assert.assertEquals(101, _basicVO.id);
			Assert.assertEquals("henk", _basicVO.name);
			
			Assert.assertEquals(1, _serializeVO.id);
			Assert.assertEquals("Engineer", _serializeVO.job);
		}
		
		[Test]
		public function testMethod() : void
		{
			Assert.assertEquals("Straat", _serializeVO.street);
			Assert.assertEquals("Land", _serializeVO.country);
			
			Assert.assertEquals("Friet, Piet", _serializeVO.name);
		}
		
		[Test]
		public function testArray() : void
		{
			Assert.assertTrue(_basicVO.mainQueue is Array);
			Assert.assertEquals("http://www.google.nl", _basicVO.mainQueue[0]['item']);
			Assert.assertEquals("http://www.google.co.uk", _basicVO.mainQueue[3]['item']);
		}
		
		[Test]
		public function testVector() : void
		{
			Assert.assertTrue(_basicVO.list is Vector.<BasicVO>);
			Assert.assertEquals(1, _basicVO.list[0].id);
			Assert.assertEquals(2, _basicVO.list[1].id);
		}
		
		[Ignore]
		[Test]
		public function testDictionary() : void
		{
			//NOTE:
			//This isn't working properly. Should check for a different solution @see XMLSerializer for documentation.
			Assert.assertTrue(_basicVO.dictionary is Dictionary);
			Assert.assertEquals("French", _basicVO.dictionary["key"]);
		}
		
		[After]
		public function teardown() : void
		{
			_xmlSerializer = null;
			
			_basicXML = null;
			_serializeXML = null;
			
			_basicVO = null;
			_serializeVO = null;
		}
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
	}

}